<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/11/13
 * Time: 17:29
 */

namespace app\api\service;


use app\api\model\Category;
use app\api\model\ProductProperty;
use think\Db;
use think\Exception;

class Property
{
    /**
     * 获取商品分类规格信息
     * @param $t_id
     * @return false|\PDOStatement|string|\think\Collection
     */
        public function getProperty($t_id){
            $category = new Category();
            $property =  $category->getProperty($t_id);
            return $property;
        }
    /**
     * 根据商品分类获取规格信息
     * @param $c_id
     * @return false|\PDOStatement|string|\think\Collection
     */
        public function getPropertyByCategory($c_id){
            $category = new ProductProperty();
            $property = $category->getPropertyByCategory($c_id);
            return $property;
        }

    /**
     * 创建商品规格
     * @param $info
     * @param $category_id
     * @return array|false|string
     * @throws Exception
     */
    public function createProperty($info,$category_id){
        $add = $info['add'];
        $delete = $info['delete'];
        $result = 'ok';
        $property = new ProductProperty();
        Db::startTrans();
        try {
            if ($add != null) {
                $result = $property->createProperty($add, $category_id);//添加
            }
            if ($delete != null) {
                $property::deleteProperty($delete);//删除
            }
            Db::commit();
        }catch (Exception $exception){
            Db::rollback();
            throw  $exception;
        }
        return $result;
    }


}